package com.dynabook.ems.model.vo;

import cn.hutool.core.collection.CollUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Date;
import java.util.List;

/**
 * BOM详情查询响应VO
 */
@Data
@ApiModel(value = "BOM详情信息", description = "BOM完整详情信息")
public class BomDetailVO {
    @ApiModelProperty(value = "BOM详情ID")
    private Long bomId;

    @ApiModelProperty(value = "BOM编号")
    private String bomNum;
    
    @ApiModelProperty(value = "产品名称前缀")
    private String productNamePrefix;
    
    @ApiModelProperty(value = "产品名称后缀")
    private String productNameSuffix;
    
    @ApiModelProperty(value = "完整产品名称")
    private String productName;
    /**
     * 成品名称
     */
    @ApiModelProperty("成品名称")
    private String finishProductName;
    
    @ApiModelProperty(value = "机型名称")
    private String machineName;
    
    @ApiModelProperty(value = "版本")
    private String version;

    @ApiModelProperty(value = "是否是最新版本")
    private Boolean isNewVersion;
    
    @ApiModelProperty(value = "关联工单")
    private List<OptionWorkOrderVO> associatedWorkOrder;
    
    @ApiModelProperty(value = "用户ID")
    private String userId;
    
    @ApiModelProperty(value = "用户名称")
    private String userName;
    
    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date insertTime;
    
    @ApiModelProperty(value = "更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;
    
    @ApiModelProperty(value = "BOM详情列表")
    private List<BomDetailItem> bomDetails;
    @ApiModelProperty(value = "是否可以编辑")
    private Boolean canEdit;
    /**
     * BOM详情项
     */
    @Data
    @ApiModel(value = "BOM详情项", description = "BOM中的具体零部件信息")
    public static class BomDetailItem {
        
        @ApiModelProperty(value = "详情ID")
        private String id;
        
        @ApiModelProperty(value = "样品型号")
        private String modelType;
        
        @ApiModelProperty(value = "样品名称")
        private String modelName;
        
        @ApiModelProperty(value = "样品数量")
        private String modelNumber;
        
        @ApiModelProperty(value = "样品单位")
        private String modelUnit;
        
        @ApiModelProperty(value = "样品分类")
        private String modelCategory;
        
        @ApiModelProperty(value = "备注")
        private String remark;

        @ApiModelProperty(value = "是否是第一条")
        private Integer isFirst;
    }
    

    
    /**
     * 计算是否可以编辑
     * 规则：associatedWorkOrder为空并且isNewVersion为true才能编辑
     */
    public void calculateCanEdit() {
        this.canEdit = (this.associatedWorkOrder == null ||
                CollUtil.isEmpty(this.associatedWorkOrder)) &&
                      Boolean.TRUE.equals(this.isNewVersion);
    }
}